﻿using System;
using System.Reflection;
using NServiceBus.Unicast;

namespace NsbExtensions.Endpoints.Msmq
{
    public class UnicastMsmqManagedEndpoint : ManagedEndpoint
    {
        protected override void RegisterMessagesAndHandlersIn(Assembly asm)
        {
            var ub = Bus as UnicastBus;
            if (ub == null)
                throw new InvalidOperationException(
                    "A UnicastBus has not been properly instantiated. RegisterMessagesAndHandlersIn requires a properly configured and instantiated UnicastBus. Ensure your configuration is correct.");

            ub.AddTypesFromAssembly(asm);
        }
    }
}